<template>
  <div class="flex">
    <div class="tableManage w-100%">
      <!-- <ContentWrap> -->
        <!-- 搜索区域 -->
        <div class="search-form">
          <Search
            :schema="allSchemas.searchSchema"
            @reset="setSearchParams"
            @search="setSearchParams"
          />
        </div>

        <ElDivider />

        <!-- 操作按钮区域 -->
        <div class="mb-10px" >
          <BaseButton
            v-if="deviceTreeStore.currentNodeKey&&currentNodeType==='设备型号'"
            class="opBtn"
            size=""
            type="primary"
            @click="AddAction"
          >
            新增
          </BaseButton>
            <BaseButton class="opBtn" size="" type="primary" @click="showFillTips">
            填报提示
          </BaseButton>
        </div>

        <!-- 数据表格 -->
        <Table
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :columns="allSchemas.tableColumns"
          :data="dataList"
          :loading="loading"
          @register="tableRegister"
          :pagination="{ total }"
        />
      <!-- </ContentWrap> -->
    </div>

    <!-- 新增/编辑/查看对话框 -->
    <Dialog width="65%" v-model="dialogVisible" :title="dialogTitle">
      <!-- 表单组件（新增/编辑时显示） -->
      <Write
        class="opWrite"
        v-if="actionType !== 'detail'"
        ref="writeRef"
        :form-schema="allSchemas.formSchema"
        :current-row="currentRow"
        :current-node-name="currentNodeName"
      />

      <!-- 详情组件（查看时显示） -->
      <Detail
        v-if="actionType === 'detail'"
        :detail-schema="allSchemas.detailSchema"
        :current-row="currentRow"
      />

      <!-- 对话框底部按钮 -->
      <template #footer>
        <BaseButton
          v-if="actionType !== 'detail'"
          type="primary"
          :loading="saveLoading"
          @click="save"
        >
          保存
        </BaseButton>
        <BaseButton @click="dialogVisible = false">关闭</BaseButton>
      </template>
    </Dialog>
    <Dialog
      v-model="fillTipsVisible"
      title="进口软件填报要求"
      width="700px"

    >
      <div class="fill-tips-content">
        <div class="tips-section">

          <div class="tips-item">
            <div v-html="fillTipsData"></div>
          </div>
        </div>
      </div>

      <template #footer>
        <BaseButton type="primary" @click="fillTipsVisible = false">确定</BaseButton>
      </template>
    </Dialog>
  </div>
</template>

<script setup lang="tsx">
import { ref, unref, reactive, watch, computed, onMounted, ComponentRef, nextTick } from "vue";
import { ContentWrap } from "@/components/ContentWrap";
import { Table } from "@/components/Table";
import { ElMessage, ElMessageBox } from "element-plus";
import { useTable } from "@/hooks/web/useTable";
import { Search } from "@/components/Search";
import Write from "./components/importedSoftwareWrite.vue";
import { useValidator } from "@/hooks/web/useValidator";
import Detail from "./components/importedSoftwareDetail.vue";
import { Dialog } from "@/components/Dialog";
import { CrudSchema, useCrudSchemas } from "@/hooks/web/useCrudSchemas";
import { BaseButton } from "@/components/Button";
import { useDictionaryStore } from "@/store/modules/dictionaryStore";
import { useDeviceTreeStore } from "@/store/modules/deviceTreeStore";
import { Edit, View, Delete } from "@element-plus/icons-vue";
import { directAxios } from "@/axios/index";
import { debounce } from 'lodash-es'
import { FORM_TYPES } from "@/utils/tips";


// ============ 初始化Store和工具函数 ============
const { required } = useValidator(); // 表单验证工具
const deviceTreeStore = useDeviceTreeStore(); // 设备树store
const dictionaryStore = useDictionaryStore(); // 字典store



// ============ 填报提示相关数据 ============
const fillTipsVisible = ref(false); // 填报提示弹框显示状态
const fillTipsData = ref(""); // 填报提示内容
const fillTipsLoading = ref(false); // 加载状态

/**
 * 加载填报提示数据
 */
const loadFillTipsData = async (): Promise<string> => {
  try {
    fillTipsLoading.value = true;
    const BASE_URL = import.meta.env.VITE_APP_BASE_URL || '/'
      const response = await fetch(`${BASE_URL}tips.json`);

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    const data = await response.json();
    return data[FORM_TYPES.IMPORTED_SOFTWARES] || "暂无填报提示信息";
  } catch (error) {
    console.error('加载填报提示数据失败:', error);
    return "加载填报提示信息失败，请稍后重试";
  } finally {
    fillTipsLoading.value = false;
  }
}

/**
 * 显示填报提示弹框
 */
const showFillTips = async () => {
  try {
    fillTipsVisible.value = true;
    // 每次显示都重新加载，确保获取最新数据
    fillTipsData.value = await loadFillTipsData();
  } catch (error) {
    console.error('显示填报提示失败:', error);
    fillTipsData.value = "加载填报提示信息失败，请稍后重试";
  }
};

// ============ 响应式数据定义 ============

// 当前节点相关
const currentNodeType = ref(""); // 当前节点类型
const currentNodeName = ref(""); // 当前节点名称
const currentNodeKey = ref(deviceTreeStore.currentNodeKey); // 当前节点key
const currentNodeKeys = ref(); // 当前节点keys

// 防抖和加载控制
const loadingLock = ref(false)
const lastRequestKey = ref('') // 记录最后一次请求的key
let currentRequestId = 0 // 请求ID追踪

// 表格相关状态 - 使用useTable hook管理表格状态
const { tableRegister, tableState, tableMethods } = useTable({
  /**
   * 获取进口软件表格数据的API
   */
  fetchDataApi: async () => {
    const { pageSize, currentPage } = tableState;
    const deviceCode = deviceTreeStore.currentNodeKey;

    // 如果没有选中设备节点，返回空数据
    if (!deviceCode) {
      return {
        list: [],
        total: 0,
      };
    }

    const res = await "/cImportedSoftwares/page".get({
      deviceCode: deviceCode,
      pageNum: unref(currentPage),
       missionCode: deviceTreeStore.taskInfo?.missionCode,
      pageSize: unref(pageSize),
      ...unref(searchParams),
    });
    return {
      list: res.data.records || [],
      total: res.data.total || 0,
    };
  },
  immediate: false, // 禁用立即执行
});

// 解构表格状态和方法
const { total, loading, dataList, pageSize, currentPage } = tableState;
const { getList } = tableMethods;

// 搜索参数
const searchParams = ref({});

// 对话框相关状态
const dialogVisible = ref(false); // 对话框显示状态
const dialogTitle = ref(""); // 对话框标题
const currentRow = ref(); // 当前操作的行数据
const actionType = ref(""); // 操作类型：'' | 'edit' | 'detail'
const saveLoading = ref(false); // 保存加载状态

// 组件引用
const writeRef = ref<ComponentRef<typeof Write>>(); // 表单组件引用

// ============ 计算属性 ============

// 是否核关高选项
const isHighlyCriticalOptions = computed(() => {
  return dictionaryStore.dictionaries.get(dictionaryStore.DICTIONARY_TYPES.YORN) || [];
});

// 自主可控等级选项
const controllableOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.INDEPENDENT_CONTROL_LEVEL
  ) || [];
});
// 对外依存度选项
const dependencyOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.EXTERNAL_DEPENDENCE
  ) || [];
});
// 进口基础产品解决途径
const solutionPlanOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.SOLUTION_PLAN
  ) || [];
});
  // 对标典型国产产品是否鉴定/验收选项
const isAcceptOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.IS_ACCEPT
  ) || [];
});
// ============ 防抖和安全获取方法 ============

/**
 * 防抖的获取列表方法
 */
const getListDebounced = debounce(async () => {
  if (loadingLock.value || loading.value) return

  const currentKey = deviceTreeStore.currentNodeKey
  if (!currentKey || !deviceTreeStore.currentTask) {
    dataList.value = []
    total.value = 0
    return
  }

  // 如果和上次请求的key相同，且数据已存在，则不重复请求
  const requestSignature = `${currentKey}-${deviceTreeStore.currentTask}`
  if (lastRequestKey.value === requestSignature && dataList.value.length > 0) {
    return
  }

  loadingLock.value = true
  lastRequestKey.value = requestSignature

  try {
    await getList()
  } finally {
    loadingLock.value = false
  }
}, 300)

/**
 * 安全获取方法
 */
const getListSafe = async () => {

  if (loadingLock.value) {
    return
  }

  if (!deviceTreeStore.currentNodeKey || !deviceTreeStore.currentTask) {
    dataList.value = []
    total.value = 0
    return
  }

  getList()
}

// ============ 监听器 ============

/**
 * 监听任务变化，当任务切换时刷新数据
 */
watch(
  () => deviceTreeStore.currentTask,
  async (newTask, oldTask) => {
    if (newTask && newTask !== oldTask) {
      currentPage.value = 1; // 重置分页
      dataList.value = []; // 清空旧数据
      searchParams.value = {} // 重置搜索条件

      // 使用nextTick确保在下一个事件循环执行
      await nextTick()

      // 生成新的请求ID
      const requestId = ++currentRequestId

      // 使用setTimeout确保在浏览器空闲时执行
      setTimeout(() => {
        // 检查是否仍然是最新的请求
        if (requestId === currentRequestId) {
          getListSafe()
        }
      }, 0)
    }
  }
);

/**
 * 监听设备树节点变化，刷新表格数据 - 主监听器
 */
watch(
  () => deviceTreeStore.currentNodeKey,
  async (newKey, oldKey) => {
    const node = deviceTreeStore.currentTreeNode
    currentNodeKey.value = newKey
    currentNodeKeys.value = newKey
    currentNodeName.value = node?.deviceName || ""
    // 设置当前节点类型
    currentNodeType.value = node?.nodeType || ""



    // 只有当节点真正变化时才刷新数据
    if (newKey && newKey !== oldKey) {
      currentPage.value = 1
      dataList.value = [] // 清空旧数据
      searchParams.value = {} // 重置搜索条件

      // 使用nextTick确保在下一个事件循环执行
      await nextTick()

      // 生成新的请求ID
      const requestId = ++currentRequestId

      // 使用setTimeout确保在浏览器空闲时执行
      setTimeout(() => {
        // 检查是否仍然是最新的请求
        if (requestId === currentRequestId) {
          getListSafe()
        }
      }, 0)
    }
  },
  { immediate: true, flush: 'post' } // 使用post确保在DOM更新后执行
);

// ============ 方法定义 ============

/**
 * 设置搜索参数并刷新表格
 * @param params 搜索参数
 */
const setSearchParams = (params: any) => {
  currentPage.value = 1;
  searchParams.value = params;
  getList();
};

/**
 * 新增操作
 */
const AddAction = () => {
  if (currentNodeType.value !== "设备型号") {
    ElMessage.error("仅设备节点可新增");
    return;
  }
  dialogTitle.value = "新增";
  currentRow.value = {
    account: currentNodeName.value, // 设置所属设备名称
  };
  dialogVisible.value = true;
  actionType.value = "";
};

/**
 * 删除数据
 * @param row 要删除的行数据
 */
const delData = async (row?: any) => {
  ElMessageBox.confirm("是否确认删除?", "提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      const params = {
        id: row?.id,
      };
      const res = await directAxios.post(
        "/cImportedSoftwares/delete",
        params,
        {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
          transformRequest: [(data) => data.toString()],
        }
      );

      if (res.code === 200) {
        ElMessage.success("删除成功");
        getList();
      }
    })
    .catch(() => {});
};

/**
 * 行操作处理（编辑/查看）
 * @param row 行数据
 * @param type 操作类型：'edit' | 'detail'
 */
const action = (row: any, type: string) => {
  dialogTitle.value = type === "edit" ? "编辑" : "查看";
  actionType.value = type;
const actualDeviceName = deviceTreeStore.getDeviceNameByCode(row.deviceCode);

  currentRow.value = {
    ...row,
    account: actualDeviceName, // 确保所属设备字段有值
  };
  dialogVisible.value = true;
};

/**
 * 保存表单数据
 */
const save = async () => {
  const write = unref(writeRef);
  const formData = await write?.submit();

  if (formData) {
    saveLoading.value = true;
    try {
      const res = await "/cImportedSoftwares/save".post({
        ...formData,
        deviceCode: currentNodeKeys.value, // 设置设备编码
        missionCode: deviceTreeStore.taskInfo?.missionCode,
      });

      if (res) {
        currentPage.value = 1;
        getList();
        dialogVisible.value = false;
        ElMessage.success("保存成功");
      }
    } catch (error) {
      console.log("保存失败:", error);
    } finally {
      saveLoading.value = false;
    }
  }
};

// ============ CRUD表结构配置 ============

/**
 * 进口软件管理表结构配置
 */
const crudSchemas = reactive<CrudSchema[]>([
  {
    field: "selection",
    search: { hidden: true },
    form: { hidden: true },
    detail: { hidden: true },
    table: { type: "selection", hidden: true },
  },
  {
    field: "index",
    label: "序号",
    form: { hidden: true },
    search: { hidden: true },
    detail: { hidden: true },
    table: { type: "index" },
  },
  {
    field: "account",
    label: "所属设备",
    width: 90,
    search: { hidden: true },
    form: {
      component: "Input",
      value: currentNodeName.value,
      componentProps: {
        placeholder: "请输入所属设备",
        disabled: true,
      },
    },
    table: { hidden: true },
  },
  {
    field: "productCategory",
    label: "进口基础产品类别",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 140,
    form: {
      formItemProps: {
        rules: [
          { required: true, message: "请输入进口基础产品类别" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入进口基础产品类别" },
        ],
      },
      componentProps: { placeholder: "请输入进口基础产品类别" },
    },
    search: { hidden: true },
  },
  {
    field: "basicProductName",
    label: "进口基础产品名称",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 150,
    form: {
      formItemProps: {
        rules: [
          { required: true, message: "请输入基础产品名称" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入基础产品名称" },
        ],
      },
      componentProps: { placeholder: "请输入基础产品名称" },
      colProps: { span: 24 },
    },
    detail: { span: 24 },
    search: {
      component: "Input",
      label: "",
      hidden: false,
      componentProps: { placeholder: "基础产品名称" },
    },
  },
     {
    field: "productVersion",
    label: "进口基础产品版本号",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 150,
    search: {
      component: "Input",
      label: "",
      hidden: true,
      componentProps: { placeholder: "进口基础产品版本号" },
    },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入进口基础产品版本号" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入进口基础产品版本号" },
        ],
      },
      componentProps: { placeholder: "请输入进口基础产品版本号" },
    },
  },
    {
    field: "quantityPerProduct",
    label: "单个设备使用该产品数量",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "InputNumber",
      formItemProps: {
        rules: [
          { required: true, message: "请输入单个设备使用该产品数量" },
          {
            validator: (rule, value, callback) => {
              if (value < 0) {
                return callback(new Error("输入值不能低于 0"));
              }
              callback();
            },
          },
        ],
      },
      componentProps: {
        type: "number",
        placeholder: "请输入单个设备使用该产品数量",
        min: 0,
          precision: 0, // 精度为0，即整数
        step:1

      },
    },
  },
    {
    field: "mainTechnicalIndicators",
    label: "进口基础产品主要技术指标",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入进口基础产品主要技术指标" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入进口基础产品主要技术指标" },
        ],
      },
      componentProps: { placeholder: "请输入进口基础产品主要技术指标" },
      colProps: { span: 24 },
    },
    detail: { span: 24 },
  },
  {
    field: "manufacturer",
    label: "进口基础产品制造商",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 150,
    search: {
      component: "Input",
      label: "",
      hidden: false,
      componentProps: { placeholder: "进口基础产品制造商" },
    },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入进口基础产品制造商" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入进口基础产品制造商" },
        ],
      },
      componentProps: { placeholder: "进口基础产品制造商" },
    },
  },
   {
    field: "benchmarkImportRegion",
    label: "进口基础产品国家/地区",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 150,
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入进口基础产品国家/地区" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入进口基础产品国家/地区" },
        ],
      },
      componentProps: { placeholder: "请输入进口基础产品国家/地区" },
      colProps: { span: 12 },
    },
    table: { hidden: true },
    detail: { span: 12 },
  },
  {
    field: "isCoreKeyProduct",
    label: "是否核关高",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 120,
    form: {
      component: "Select",
      value: "",
      formItemProps: {
        rules: [{ required: true, message: "请选择是否核关高" }],
      },
      componentProps: { options: isHighlyCriticalOptions },
    },
    search: {
      component: "Select",
      label: "是否核关高",
      showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
      hidden: false,
      componentProps: {
        placeholder: "是否核关高",
        options: isHighlyCriticalOptions,
      },
    },
  },
   {
    field: "externalDependence",
    label: "对外依存度",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Select",
      value: "",
      componentProps: {
        placeholder: "对外依存度",
        options: dependencyOptions,
      },
      formItemProps: {
        rules: [{ required: true, message: "请选择对外依存度" }],
      },
    },
  },
    {
    field: "solutionPlan",
    label: "进口基础产品解决途径",
    width: 80,
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    table: { hidden: true },
    search: {
      component: "Select",
      label: "",
      hidden: true,
      componentProps: {
        placeholder: "进口基础产品解决途径",
        options: solutionPlanOptions,
      },
    },
    form: {
      component: "Select",
      formItemProps: {
        rules: [{ required: true, message: "请选择进口基础产品解决途径" }],
      },
      componentProps: {
        placeholder: "请选择进口基础产品解决途径",
        options: solutionPlanOptions,
      },
    },
  },
   {
    field: "supplier",
    label: "进口基础产品供货商",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 170,
    search: {
      component: "Input",
      label: "",
      hidden: false,
      componentProps: { placeholder: "进口基础产品供货商" },
    },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入进口基础产品供货商" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入进口基础产品供货商" },
        ],
      },
      componentProps: { placeholder: "请输入进口基础产品供货商" },
    },
  },
      {
    field: "launchTime",
    label: "进口基础产品上市时间",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 80,
    search: {
      component: "Input",
      label: "",
      hidden: true,
      componentProps: { placeholder: "进口基础产品上市时间" },
    },
    form: {
      component: "DatePicker",
      formItemProps: {
        rules: [{ required: true, message: "请选择进口基础产品上市时间" }],
      },
      componentProps: {
        type: "month",
        valueFormat: "YYYY-MM", // 添加这一行
        placeholder: "请输入进口基础产品上市时间",
      },
    },
    table: { hidden: true },
  },
    {
    field: "referencePrice",
    label: "参考价格(万元)",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 120,
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入参考价格" },
          {
            validator: (rule, value, callback) => {
              if (value < 0) {
                return callback(new Error("输入值不能低于 0"));
              }
              callback();
            },
          },
        ],
      },
      componentProps: {
        type: "number",
        placeholder: "请输入参考价格",
        min: 0,

        // precision: 2,
      },
    },
  },
    {
    field: "basicProductUser",
    label: "进口基础产品使用负责人",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 80,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入进口基础产品使用负责人" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入进口基础产品使用负责人" },
        ],
      },
      componentProps: { placeholder: "请输入进口基础产品使用负责人" },
    },
  },
  {
    field: "userContactInfo",
    label: "进口基础产品使用人联系方式",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入进口基础产品使用人联系方式" },
          { pattern: /^[0-9]{11}$/, message: "请输入正确的进口基础产品使用人联系方式" },
        ],
      },
      componentProps: { placeholder: "请输入进口基础产品使用人联系方式" },
    },
    detail: { span: 12 },
  },



  {
    field: "domesticProductName",
    label: "对标典型国产产品名称",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 140,
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入对标典型国产产品名称" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入对标典型国产产品名称" },
        ],
      },
      componentProps: { placeholder: "请输入对标典型国产产品名称" },
    },
  },
    {
    field: "domesticProductSpecification",
    label: "对标典型国产产品规格",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 80,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入对标典型国产产品规格" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入对标典型国产产品规格" },
        ],
      },
      componentProps: { placeholder: "请输入对标典型国产产品规格" },
    },
  },

  {
    field: "domesticProductIsAcceptance",
    label: "对标典型国产产品是否鉴定/验收",
    width: 150,
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    search: {
      component: "Select",
      label: "",
      hidden: true,
      componentProps: { placeholder: "请输入对标典型国产产品是否鉴定/验收" },

    },
    form: {
      component: "Select",
      formItemProps: {
        rules: [
          { required: true, message: "请输入对标典型国产产品是否鉴定/验收" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入对标典型国产产品是否鉴定/验收" },
        ],
      },
      componentProps: { placeholder: "请输入对标典型国产产品是否鉴定/验收",
      options:isAcceptOptions,

       },
    },
    table: { hidden: true },
  },
  {
    field: "domesticProductIdentificationUnit",
    label: "对标典型国产产品鉴定/验收单位",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 150,
    search: {
      component: "Input",
      label: "",
      hidden: true,
      componentProps: { placeholder: "请输入对标典型国产产品鉴定/验收单位" },
    },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入对标典型国产产品鉴定/验收单位" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入对标典型国产产品鉴定/验收单位" },
        ],
      },
      componentProps: { placeholder: "请输入对标典型国产产品鉴定/验收单位" },
    },
    table: { hidden: true },
  },
    {
    field: "domesticProductDevelopmentUnit",
    label: "对标典型国产产品研制单位",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 150,
    search: {
      component: "Input",
      label: "",
      hidden: true,
      componentProps: { placeholder: "请输入对标典型国产产品研制单位" },
    },
    detail: { span: 24 },
    form: {
      component: "Input",
      colProps: { span: 24 },
      formItemProps: {
        rules: [
          { required: true, message: "请输入对标典型国产产品研制单位" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入对标典型国产产品研制单位" },
        ],
      },
      componentProps: { placeholder: "请输入对标典型国产产品研制单位" },
    },
    table: { hidden: true },
  },
  {
    field: "domesticProductPersonInCharge",
    label: "对标典型国产产品负责人",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 140,
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入对标典型国产产品负责人" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入对标典型国产产品负责人" },
        ],
      },
      componentProps: { placeholder: "请输入对标典型国产产品负责人" },
    },
  },
  {
    field: "domesticProductContactInfo",
    label: "对标典型国产产品联系方式",
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    width: 150,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      componentProps: { placeholder: "请输入对标典型国产产品联系方式" },
      formItemProps: {
        rules: [
          { required: true, message: "请输入对标典型国产产品联系方式" },
          { pattern: /^[0-9]{11}$/, message: "请输入正确的对标典型国产产品联系方式" },
        ],
      },
      colProps: { span: 12 },
    },
  },
  {
    field: "remarks",
    label: "备注",
    width: 90,
    showTip: true, // 启用提示
    tipConfig: {
      formType: FORM_TYPES.IMPORTED_SOFTWARES,
    },
    search: { hidden: true },
    detail: { span: 24 },
    form: {
      component: "Input",
      componentProps: {
        type: "textarea",
        rows: 3,
        placeholder: "请输入备注信息",
      },
      colProps: { span: 24 },
    },
    table: { hidden: true },
  },
  {
    field: "action",
    label: "操作",
    fixed: "right",
    form: { hidden: true },
    detail: { hidden: true },
    search: { hidden: true },
    table: {
      width: 170,
      fixed: "right",
      slots: {
        default: (data: any) => {
          const row = data.row;
          return (
            <>
              <div style="display:flex;color: var(--el-color-primary)">
                <div class="flex-1 cursor-pointer" onClick={() => action(row, "edit")}>
                  <el-icon>
                    <Edit />
                  </el-icon>
                  编辑
                </div>
                <div class="flex-1 cursor-pointer" onClick={() => action(row, "detail")}>
                  <el-icon>
                    <View />
                  </el-icon>
                  查看
                </div>
                <div class="flex-1 cursor-pointer" onClick={() => delData(row)}>
                  <el-icon>
                    <Delete />
                  </el-icon>
                  删除
                </div>
              </div>
            </>
          );
        },
      },
    },
  },
]);

// 使用CRUD Schemas hook
// const { allSchemas } = useCrudSchemas(crudSchemas);

// ============ 生命周期 ============
const { allSchemas } = useCrudSchemas(crudSchemas, {
  showTips: true, // 这里必须设置为 true
  defaultFormType: FORM_TYPES.IMPORTED_SOFTWARES,
});
/**
 * 组件挂载时初始化
 */
onMounted(async () => {
  // 预加载常用字典
  await dictionaryStore.preloadCommonDictionaries();

  // 设置当前节点名称
  currentNodeName.value = deviceTreeStore.currentTreeNode?.deviceName || "";

  // 设置当前节点类型
  currentNodeType.value = deviceTreeStore.currentTreeNode?.nodeType || "";

  // 注意：不要在mounted中调用getList，让watch的immediate处理
});

defineExpose({
  getList: getListSafe
   // 暴露安全版本
});
</script>

<style scoped lang="less">
:deep(.el-divider--horizontal) {
  margin: 5px 0 15px 0;
}

.mb-10px {
  display: flex;
}
:deep(.el-card__body ){
  padding: 20px  0 !important;
}
</style>
